/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 16:56:57
 * @LastEditTime: 2021-08-30 16:58:17
 * @LastEditors: changqing
 * @Usage: 
 */
var { timer, interval,range,from,Subject } = require('rxjs'); 
var {sampleTime,map} = require('rxjs/operators');

// sampleTime有定期取样的意思，可以指定一个时间，当Observable被订阅时，就会依据指定的时间，每经过这段时间就从来源Observable内取这段时间最近一次的数据

const source = new Subject();
source.pipe(
  sampleTime(1500)
).subscribe(data => {
  console.log(` ${data}`);
});
setTimeout(() => source$.next(1), 0);
setTimeout(() => source$.next(2), 500);
setTimeout(() => source$.next(3), 1000);
setTimeout(() => source$.next(4), 4000);
setTimeout(() => source$.next(5), 5000);
setTimeout(() => source$.complete(), 5500);
// 3 4
